<!-- 登陆页面----------01 -->
<template>
  <div class="quest">
    <img src="../../assets/logg.png" alt="" class="images" />
    <div class="ones">
      <img src="../../assets/orange@3x.png" alt="" class="imagee" />

      <!-- 用element写一个登陆界面 -->

      <div class="nbhz">
        <!-- 用element写一个登陆界面 -->
        <el-form
          :model="ruleForm"
          :rules="rules"
          ref="ruleForm"
          label-width="100px"
          class="demo-ruleForm"
        >
          <el-form-item label="用户名" prop="username">
            <el-input v-model="ruleForm.username"></el-input>
          </el-form-item>
          <el-form-item label="密码" prop="password">
            <el-input
              type="password"
              v-model="ruleForm.password"
              autocomplete="off"
            ></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="submitForm('ruleForm')"
              >登陆</el-button
            >
            <el-button @click="resetForm('ruleForm')">重置</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "Login",
  data() {
    return {
      ruleForm: {
        username: "",
        password: "",
      },
      rules: {
        username: [
          { required: true, message: "请输入用户名", trigger: "blur" },
          { min: 3, max: 6, message: "长度在 3 到 5 个字符", trigger: "blur" },
        ],
        password: [
          { required: true, message: "请输入密码", trigger: "blur" },
          {
            min: 6,
            max: 12,
            message: "长度在 6 到 12 个字符",
            trigger: "blur",
          },
        ],
      },
    };
  },

  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$api.reqLogin(this.ruleForm).then((res) => {
            console.log(res);
            // 存储用户信息
            // localStorage.setItem("token", JSON.stringify(res.data.list));

          });
          alert("submit!");
          // 跳转到index页面
          this.$router.push("/index");
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
  },
  created() {},
  mounted() {
    console.log("获取分类数据");
    // 获取数据
    // 请求登陆借口
    // localStorage.setItem("token",JSON.stringify (res.data.list));
    // });
  },
  components: {},
  computed: {},
  watch: {},
};
</script>

<style scopend lang="scss">
.nbhz {
  margin-top: 40%;
}

.imagee {
  width: 90%;
  margin-left: 5%;
}
.ones {
  width: 30%;
  height: 60%;
  // 靠近左侧
  position: absolute;
  left: 62%;
  top: 20%;
}

.quest {
  width: 100vw;
  height: 100vh;
  background-color: #ff6040;
  position: relative;
}
.images {
  width: 60%;
  height: 80%;
  // 靠近右侧
  float: right;
  margin-top: 5%;
  position: absolute;
  left: 35%;

  // 子绝父相
}
</style>
